package org.example;

import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.lang.reflect.InvocationTargetException;

public class UserTest {

    private Logger logger = LoggerFactory.getLogger(UserTest.class);
    @Test
    public void test(){
        ApplicationContext context =new ClassPathXmlApplicationContext("bean.xml");
        User user = context.getBean("user", User.class);
        System.out.println("user = " + user);
        user.add();
        logger.info("添加方法调用成功");

    }


    @Test
    public void reflect() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        Class<?> aClass = Class.forName("org.example.User");
        User o = (User)aClass.getDeclaredConstructor().newInstance();
        o.add();

    }
}
